<template>
  <div>
    <div><h1>商户列表</h1></div>
    <div>
      <el-table :data="tableData" stripe style="width: 100%">
        <el-table-column prop="userId" label="ID" width="50" />
        <el-table-column prop="userName" label="商户名称" width="120" />
        <el-table-column prop="userMobile" label="商户电话号" width="120" />
        <el-table-column prop="userEmail" label="商户邮箱" width="100" />
        <el-table-column prop="userGender" label="商户性别" width="100" />
        <el-table-column prop="userAvatar" label="商户头像" width="100" />
        <el-table-column prop="createTime" label="创建时间" width="180" />
        <el-table-column label="操作" width="100" />
      </el-table>
    </div>
    <div>
      <div>
        <div class="demo-pagination-block">
          <el-pagination
            v-model:current-page="searchForm.pageNum"
            v-model:page-size="searchForm.pageSize"
            :page-sizes="[2, 4, 6, 8]"
            :background="true"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, reactive, ref } from "vue";
import { getUserList } from "../api/api";

const tableData = ref([]);
const total = ref(0);

const searchForm = ref({
  pageNum: 1,
  pageSize: 2,
  keyWord: "",
});

//分页
const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`);
  searchForm.value.pageSize = val;
  loadList();
};
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`);
  searchForm.value.pageNum = val;
  loadList();
};

//获取列表
const loadList = () => {
  getUserList(searchForm.value).then((res) => {
    if (res.data.code == 200) {
      tableData.value = res.data.data.records;
      total.value = res.data.data.total;
    }
  });
};

//初始化数据
onMounted(() => {
  loadList();
});
</script>

<style scoped></style>
